package vistas;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import clases.Seccion;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FrmSeccion extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JButton jButton1;
	private AbstractAction abstractAction1;
	private AbstractAction abstractAction2;
	private JButton jButton2;
	private AbstractAction Salir;
	private JTextField numero;
	private Seccion seccion = null;
	
	

	public Seccion getSeccion() {
		return seccion;
	}

	public void setSeccion(Seccion seccion) {
		this.seccion = seccion;
	}
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				FrmSeccion inst = new FrmSeccion();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public FrmSeccion() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Registro de Seccion");
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Nro de La Seccion");
				jLabel1.setBounds(54, 58, 137, 15);
			}
			{
				numero = new JTextField();
				getContentPane().add(numero);
				numero.setBounds(203, 55, 114, 22);
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("jButton1");
				jButton1.setBounds(84, 119, 94, 22);
				jButton1.setAction(getAbstractAction1());
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("jButton2");
				jButton2.setBounds(195, 119, 86, 22);
				jButton2.setAction(getAbstractAction2());
			}
			pack();
			this.setSize(399, 225);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private AbstractAction getAbstractAction1() {
		if(abstractAction1 == null) {
			abstractAction1 = new AbstractAction("Crear", null) {
				public void actionPerformed(ActionEvent evt) {
					if (numero.getText().isEmpty()){
						JOptionPane.showMessageDialog(new JFrame(),"Existen campos vacios","Registro de Se",JOptionPane.WARNING_MESSAGE);
						return;			
					}
					try {
						int num = Integer.parseInt(numero.getText());
						if( num<=0){
							JOptionPane.showMessageDialog(new JFrame(),"Ingrese  un numero valido","Registro de Seccion",JOptionPane.WARNING_MESSAGE);
							return;
						}
						else{
							seccion.setNum_Seccion(num);
							JOptionPane.showMessageDialog(new JFrame(),"La seccion se creo exitosamente","Registro de Seccion",JOptionPane.INFORMATION_MESSAGE);
							numero.setText("");
						}
							
					}catch (NumberFormatException ex) {
						JOptionPane.showMessageDialog(new JFrame(),"Ingrese  un numero valido","Registro de Seccion",JOptionPane.WARNING_MESSAGE);
						return;
					}
				}
				
			};
		}
		return abstractAction1;
	}
	
	private AbstractAction getSalir() {
		if(Salir == null) {
			Salir = new AbstractAction("abstractAction2", null) {
				public void actionPerformed(ActionEvent evt) {
				}
			};
		}
		return Salir;
	}
	
	private AbstractAction getAbstractAction2() {
		if(abstractAction2 == null) {
			abstractAction2 = new AbstractAction("Salir", null) {
				public void actionPerformed(ActionEvent evt) {
					dispose();
				}
			};
		}
		return abstractAction2;
	}

}
